package com.example.exam.mapper;

import com.example.exam.pojo.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.Set;

@Mapper
public interface UserRoleMapper {

    @Insert("INSERT INTO user_role (user, role) VALUES " +
            "(#{user}, #{role})")
    int insertUserRole(UserRole userRole);

    @Delete("delete table user_role where  user = #{id} ")
    int deleteUserRoleByUserId(Long id);

    @Select("SELECT  r.name FROM user as u JOIN  user_role as us ON u.id=us.user "+
            "JOIN  role as r ON  r.id=us.role WHERE  u.id=#{id} ")
    Set<String> selectRoleByUserId(Long id);

}
